local hx__jueying_ang = fk.CreateSkill {
  name = "hx__jueying_ang",
  tags = { Skill.Limited },
}

hx__jueying_ang:addEffect("active", {
  name = "hx__jueying_ang",
  card_num = 0,
  target_num = 1,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0
  end,
  prompt = "#hx__jueying_ang-juexing",
  can_use = function(self, player)
    return player:hasSkill(hx__jueying_ang.name) and #player:getAvailableEquipSlots() > 0 and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local to = effect.tos[1]
    local choice = room:askToChoice(player, {
      choices = player:getAvailableEquipSlots(),
      skill_name = hx__jueying_ang.name,
      prompt = "#hx__jueying_ang-feichu",
    })
    room:abortPlayerArea(player, choice)
    if player.dead then return end
    if #choice > 0 then
      room:handleAddLoseSkills(to, "hx__feiying", nil, true, false)
      room:handleAddLoseSkills(to, "hx__mashu", nil, true, false)
      room:addPlayerMark(to, "hx__jueying_ang_mark", 1)
    end
  end,
})

hx__jueying_ang:addEffect(fk.AfterDying, {
  mute = true,
  prompt = "#hx__jueying_ang_prompt",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    if event == fk.AfterDying then
      return player:hasSkill(hx__jueying_ang.name) and not player:isNude() and target:getMark("hx__jueying_ang_mark") ~= 0
      and #player:getAvailableEquipSlots() > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(hx__jueying_ang.name)
    player.room:doAnimate("InvokeSkill", {
      name = "hx__jueying_ang",
      player = player.id,
      skill_type = "defensive",
    })
    local slots = table.simpleClone(player.sealedSlots)
    table.removeOne(slots, Player.JudgeSlot)
    local hx__jueying_ang_recover = room:askToChoice(player, {
      choices = slots,
      skill_name = hx__jueying_ang.name,
      prompt = "#hx__jueying_ang-recover"
    })
    room:resumePlayerArea(player, {hx__jueying_ang_recover})
    room:setPlayerMark(target, "hx__jueying_ang_mark", 0)
  end,
})

return hx__jueying_ang 